package com.five.sbgroup5job.service.impl;
//胡进茹
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.five.sbgroup5job.entity.Buy;
import com.five.sbgroup5job.mapper.BuyMapper;
import com.five.sbgroup5job.service.BuyService;
import com.five.sbgroup5job.vo.BuyVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
* @author hujinru
* @description 针对表【buy】的数据库操作Service实现
* @createDate 2024-11-08 11:13:10
*/
@Service
public class BuyServiceImpl extends ServiceImpl<BuyMapper, Buy>
    implements BuyService {
    @Resource
    private BuyMapper buyMapper;

    @Override
    public List<Buy> buylist() {
        return buyMapper.selectList(null);
    }

    @Override
    public String buyAdd(BuyVo buyVo) {
        Buy buy = new Buy();
        buy.setName(buyVo.getName());
        buy.setWeight(buyVo.getWeight());
        buy.setQuantity(buyVo.getQuantity());
        buy.setPrice(buyVo.getPrice());
        buy.setTime(new Date());
        int result = buyMapper.insert(buy);
        if (result >0) {
            return "添加成功";
        }else {
            return "添加失败";
        }
    }
    @Override
    public String buyUpdate(BuyVo buyVo) {
        Buy buy = new Buy();
        buy.setId(buyVo.getId());
        buy.setName(buyVo.getName());
        int result = buyMapper.updateById(buy);
        if (result > 0) {
           return "修改成功";
        } else {
            return "修改失败";
        }

    }
    //删除
    @Override
    public String buyDelete(BuyVo buyVo) {
        int result = buyMapper.deleteById(buyVo.getId());
        if (result > 0) {
            return "删除成功";
        } else {
            return "删除失败";
        }
    }


}




